package org.coopac.controller.util;

import java.io.Serializable;
import java.util.ArrayList;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;

import org.coopac.service.IPersonaService;

import antlr.collections.List;

@ManagedBean(name="autocom")
@SessionScoped
public class AutoComplete implements Serializable{


	
	public String txt1;
	

    
    java.util.List<String> listaPersonas;
    
    @ManagedProperty(value = "#{personaService}")
	IPersonaService personaServicio;
    


	public java.util.List<String> autoCompletado(String query){
		listaPersonas = personaServicio.listarPersonaDocumento();
		java.util.List<String> results = new ArrayList<String>();  
        int limite = 0;
		try {
	        for (String persona:listaPersonas) {  
	        	if(persona.indexOf(query)>=0 && limite<=10 && query!=" "){
	        		results.add(persona);	        		
	        	}
	        	limite++;
	        }  
		} catch (Exception e) { e.printStackTrace();
		}
          
        return results; 
		  
	}
	
	public void captura(ActionEvent event){
		System.out.println("listo!:"+txt1.substring(txt1.lastIndexOf("-")+2));		
	}
	
	
	public IPersonaService getPersonaServicio() {
		return personaServicio;
	}

	public void setPersonaServicio(IPersonaService personaServicio) {
		this.personaServicio = personaServicio;
	}

	public java.util.List<String> getListaPersonas() {
		return listaPersonas;
	}

	public void setListaPersonas(java.util.List<String> listaPersonas) {
		this.listaPersonas = listaPersonas;
	}

	public String getTxt1() {
		return txt1;
	}

	public void setTxt1(String txt1) {
		this.txt1 = txt1;
	}

	
	
}
